<template>
  <div class="lang">
    <el-dropdown @command="command">
      <svg-icon icon-class="language" />
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item
            command="zh"
            :disabled="$i18n.locale === 'zh'"
          >中文</el-dropdown-item>
          <el-dropdown-item
            command="en"
            :disabled="$i18n.locale === 'en'"
          >English</el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<script>
import jsCookie from 'js-cookie'
export default {
  name: 'Lang',
  inject: ['reload'],
  methods: {
    command(command) {
      this.$i18n.locale = command
      jsCookie.set('lang', command)
      this.reload()
    }
  }
}
</script>

<style lang="scss" scoped>
.lang {
  margin-right: 20px;
  line-height: 50px;
  svg {
    color: #fff;
    width: 20px;
    height: 20px;
  }
}
</style>
